﻿//////////////////////////////////////////////////////////////////////////////////////
///// Background.cs                                                  /////
///// 기본 배경 화면(복도를 전진하는 애니메이션) /////
//////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace Pyramid_Game
{
    public class Background : GameScreen
    {
        #region Declarations

        Texture2D backgroundTexture;
        double moveTime;

        public enum State
        {
            Active,
            Pause
        }
        public State state = State.Pause;

        #endregion

        #region Property

        public Texture2D BackgroundTexture
        {
            set { backgroundTexture = value; }
            get { return backgroundTexture; }
        }
        public double MoveTime
        {
            set { moveTime = value; }
            get { return moveTime; }
        }

        #endregion

        #region Load
        
        public Background() {   }

        public override void LoadContent(ContentManager content)
        {
            backgroundTexture = content.Load<Texture2D>("Texture/play");
        }

        #endregion

        #region Update & Draw

        public override void Update(Touch touch, GameTime gameTime)
        {
            //시간을 저장 1초간 전진 애니메이션이 출력되도록
            if (state == State.Pause)
            {
                moveTime = gameTime.TotalGameTime.TotalSeconds;
                state = State.Active;
            }
            
            if (moveTime + 1 < gameTime.TotalGameTime.TotalSeconds)
            {
                switch (Map.floors[Map.playerPoint].State)
                {
                    case "START":
                        Map.playerPoint = Map.floors[Map.playerPoint].NextIndex;
                        break;
                    case "GAME":
                        screenManager.AddScreen(new GamePlay());
                        screenManager.RemoveScreen(this);
                        break;
                    case "FORK":
                        screenManager.AddScreen(new Crossroad());
                        screenManager.RemoveScreen(this);
                        break;
                    case "TURN":
                        screenManager.AddScreen(new TurningRoad());
                        screenManager.RemoveScreen(this);
                        break;
                    case "BADEND":
                        screenManager.AddScreen(new BadEnd());
                        screenManager.RemoveScreen(this);
                        break;
                    case "END":
                        screenManager.AddScreen(new End());
                        screenManager.RemoveScreen(this);
                        break;
                }
            }
        }
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            spriteBatch.Draw(backgroundTexture, Vector2.Zero, Color.White);
        }

        #endregion
    }
}
